package com.czl.base.binding.viewadapter.textview

import android.graphics.Color
import android.util.TypedValue
import android.widget.TextView
import androidx.databinding.BindingAdapter
import com.blankj.utilcode.util.ColorUtils
import com.czl.base.R
import com.czl.base.widget.SlantedTextView

object ViewAdapter {
    /**
     * TextView字体是否加粗
     */
    @JvmStatic
    @BindingAdapter(value = ["isBold"], requireAll = false)
    fun isBold(textView: TextView, isBold: Boolean) {
        val paint = textView.paint;
        paint.isFakeBoldText = isBold
    }

    /**
     * TextView字体是否加粗
     */
    @JvmStatic
    @BindingAdapter(value = ["setTextColor"], requireAll = false)
    fun setTextColor(textView: TextView, color: String) {
        textView.setTextColor(Color.parseColor(color))
    }

    /**
     * TextView字体是否加粗
     */
    @JvmStatic
    @BindingAdapter(value = ["setTextSize"], requireAll = false)
    fun setTextSize(textView: TextView, size: Float) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, size)
    }

    /**
     * 倾斜标签
     */
    @JvmStatic
    @BindingAdapter(value = ["setSlantedText"], requireAll = false)
    fun setSlantedText(stv: SlantedTextView, text: String) {
        stv.text = text
    }

    /**
     * 倾斜标签
     */
    @JvmStatic
    @BindingAdapter(value = ["slantedBackground"], requireAll = false)
    fun setSlantedText(stv: SlantedTextView, id: Int) {
        stv.setSlantedBackgroundColor(id)
    }

    /**
     * 设置支付TextView字体颜色
     */
    @JvmStatic
    @BindingAdapter(value = ["setPayTextColor"], requireAll = false)
    fun setPayTextColor(textView: TextView, payResult: String) {
        var color: Int = when (payResult) {
            "取消支付" -> R.color.color_999999
            "支付成功" -> R.color.color_00A468
            "支付失败" -> R.color.color_FF0000
            "待支付" -> R.color.color_FF6F00
            else -> R.color.color_00A468
        }
        textView.setTextColor(ColorUtils.getColor(color))
    }

    /**
     * 设置添加记录TextView字体颜色
     */
    @JvmStatic
    @BindingAdapter(value = ["setRecordTextColor"], requireAll = false)
    fun setRecordTextColor(textView: TextView, applyStatus: Int) {
        var color: Int = when (applyStatus) {
            3 -> R.color.color_FF6F00
            else -> R.color.color_00A468
        }
        textView.setTextColor(ColorUtils.getColor(color))
    }

}

